package org.chengn.level_middle.context2938;

/**
 * @author GengMY
 * @date 2024/6/6
 * @Description
 */
public class Context2938 {
    public long minimumSteps(String s) {
        int zeroIdx = 0, oneIdx = s.length() - 1;
        long res = 0;
        for (int i = 0; i < s.length(); ++i) {
            char ch = s.charAt(i);
            if (ch == '0') {
                res += (i - zeroIdx++);
            }
        }
        for (int i = s.length() - 1; i >= 0; --i) {
            char ch = s.charAt(i);
            if (ch == '1') {
                res += (oneIdx-- - i);
            }
        }

        return res / 2;
    }
}
